home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4447 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: news.kei.com!ub!newserve!rebecca!rpi!not-for-mail
  2. From: reckdahl@leland.Stanford.EDU (Keith Reckdahl)
  3. Newsgroups: comp.lang.c++,comp.lang.c++.moderated
  4. Subject: Pointer Typecasts
  5. Date: 30 Jan 1996 00:13:29 -0000
  6. Organization: Stanford University, CA 94305, USA
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: vandevod@cs.rpi.edu
  9. Message-ID: <4ejnr9$cpf@netlab.cs.rpi.edu>
  10. NNTP-Posting-Host: netlab.cs.rpi.edu
  11. X-Original-Date: 29 Jan 1996 15:15:40 -0800
  12.  
  13. We've been having problems with the following pointer 
  14. typecast: We have 4 classes A,B,C, and D
  15.   B inherits from A
  16.   C inherits from A
  17.   D inherits from both B and C
  18. Note: We've have also tried to inherit D from B and C 
  19. using the virtual keyword so that only one instance 
  20. of A is instantiated, but this does not seem to affect 
  21. the problem.  We try to typecast a pointer from A to D 
  22. meaning, in the code, we have
  23.   A  *a1;
  24.   D  *d1;
  25.   d1 = (D *)a1;
  26. And this does not work.  We get an illegal typecast 
  27. compiler error.  We've tried this on a variety of 
  28. compilers, including CODE WARRIOR, BORLAND, and MPW.
  29.  
  30. We thought that typecasting pointers is a simple 
  31. matter because all pointers are simply addresses. 
  32. What are we doing wrong?
  33.  
  34. Keith Reckdahl, Paul Mitiguy, Margaret Becker
  35. reckdahl@leland.stanford.edu
  36.  
  37.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  38.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  39.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  40.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  41.